// utils/request.js
const BASE_URL = 'http://192.168.0.151';

function request(options) {
    const { url, method = 'GET', data = {}, header = {} } = options;
    return new Promise((resolve, reject) => {
        wx.request({
            url: `${BASE_URL}${url}`,
            method,
            data,
            header,
            success: res => res.statusCode === 200 ? resolve(res.data) : reject(new Error(`请求失败，状态码：${res.statusCode}`)),
            fail: reject
        });
    });
}

function get(url, data = {}, header = {}) {
    return request({ url, method: 'GET', data, header });
}

function post(url, data = {}, header = {}) {
    return request({ url, method: 'POST', data, header });
}

function put(url, data = {}, header = {}) {
    return request({ url, method: 'PUT', data, header });
}

module.exports = {
    get,
    post,
    put
};    